package helloworld.admin.action.news;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import helloworld.admin.bean.NewsAdminBean;
import helloworld.admin.form.news.NewsSearchForm;
import helloworld.delegate.news.NewsListDelegate;

/**
 * 
 * @author TUYEN-DM
 * @version $Revision: $ $Date:2009/05/25 $
 */
public class NewsSearchAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		ActionForward forward = null;

		NewsSearchForm searchform = (NewsSearchForm) form;

		if ((searchform.getSearchButton().isSelected())
				|| ("Search".equals(request.getParameter("action")))) {
			NewsListDelegate delegate = new NewsListDelegate();
			NewsAdminBean[] news = delegate.findNews(searchform.getNewsTitle());
			request.setAttribute("NEWS_DETAIL_OBJECTS", news);
			forward = mapping.findForward("success");
		}

		return forward;
	}

}
